//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows.Documents;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public class TextField : RunBase
    {
        private string id;
        private TextParagraphProperties pPr;
        private TextCharacterProperties rPr;
        private string t;
        private string type;

        public string Text
        {
            get { return t; }
            set { t = value; }
        }


        public TextParagraphProperties TextParagraphProperties
        {
            get { return pPr; }
            set { pPr = value; }
        }

        public TextCharacterProperties TextCharacterProperties
        {
            get { return rPr; }
            set { rPr = value; }
        }


        public string Id
        {
            get { return id; }
            set { id = value; }
        }

        public string Type
        {
            get { return type; }
            set { type = value; }
        }


        internal override Inline Inline
        {
            get { throw new NotImplementedException(); }
        }

        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read("fld"))
            {
                id = c.GetOptionalString("id");
                type = c.GetOptionalString("type");
                TextCharacterProperties = c.ReadOptionalElementAs<TextCharacterProperties>("rPr");
                TextParagraphProperties = c.ReadOptionalElementAs<TextParagraphProperties>("pPr");
                Text = c.ReadOptionalElementString("t");
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write("fld"))
            {
                c.SetOptionalString("id", id);
                c.SetOptionalString("type", type);
                c.WriteOptionalElementAs(TextCharacterProperties, "rPr");
                c.WriteOptionalElementAs(TextParagraphProperties, "pPr");
                c.WriteOptionalElementString("t", Text);
            }
        }
    }
}